/* GUI CONVERTED from reisrc02.p (converter v1.76) Thu Jul 18 21:54:29 2002 */
/* reisrc02.p - REPETITIVE FEEDBACK ASSEMBLY RECEIPT FROM LABOR TRANSACTION   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.8.4.8 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 6.0      LAST MODIFIED: 06/18/90   BY: emb                       */
/* REVISION: 6.0      LAST MODIFIED: 10/10/90   BY: SMM *D085*                */
/* REVISION: 6.0      LAST MODIFIED: 12/17/90   BY: WUG *D619*                */
/* REVISION: 6.0      LAST MODIFIED: 08/01/91   BY: emb *D805*                */
/* REVISION: 6.0      LAST MODIFIED: 09/12/91   BY: WUG *D858*                */
/* REVISION: 6.0      LAST MODIFIED: 10/03/91   BY: alb *D887*                */
/* REVISION: 6.0      LAST MODIFIED: 11/11/91   BY: WUG *D920*                */
/* REVISION: 7.0      LAST MODIFIED: 02/12/92   BY: pma *F190*                */
/* REVISION: 7.3      LAST MODIFIED: 09/27/93   By: jcd *G247*                */
/* REVISION: 7.3      LAST MODIFIED: 01/22/93   BY: emb *G689*                */
/* REVISION: 7.3      LAST MODIFIED: 03/02/93   BY: emb *G767*                */
/* REVISION: 7.3      LAST MODIFIED: 09/15/94   by: slm *GM63*                */
/* REVISION: 7.3      LAST MODIFIED: 11/08/94   by: ljm *GO33*                */
/* REVISION: 8.5      LAST MODIFIED: 12/09/94   BY: taf *J038*                */
/* REVISION: 8.5      LAST MODIFIED: 01/06/95   BY: ktn *J041*                */
/* REVISION: 8.5      LAST MODIFIED: 06/07/95   BY: sxb *J04D*                */
/* REVISION: 8.5      LAST MODIFIED: 07/31/95   BY: kxn *J069*                */
/* REVISION: 7.2      LAST MODIFIED: 08/17/95   BY: qzl *F0TC*                */
/* REVISION: 8.5      LAST MODIFIED: 09/09/95   BY: kxn *J07K*                */
/* REVISION: 8.5      LAST MODIFIED: 10/27/95   BY: kxn *J092*                */
/* REVISION: 8.5      LAST MODIFIED: 03/11/96   BY: jpm *J0F5*                */
/* REVISION: 8.5      LAST MODIFIED: 10/21/96   BY: *G2H7* Julie Milligan     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.5      LAST MODIFIED: 04/15/98   BY: *J2K7* Fred Yeadon        */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 06/28/00   BY: *N0DM* Rajinder Kamra     */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 09/25/00   BY: *N0WD* BalbeerS Rajput    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.8.4.6    BY: Jean Miller        DATE: 05/21/02  ECO: *P05V*  */
/* $Revision: 1.8.4.8 $   BY: Ashish Maheshwari  DATE: 07/17/02  ECO: *N1GJ*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DECLARE COMMON VARIABLES */
{mfdeclre.i}
{cxcustom.i "REISRC02.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define output parameter tr-ok as logical no-undo.
define output parameter undo-update like mfc_logical no-undo.

define new shared variable prev_status like wo_status.
define new shared variable prev_qty like wo_qty_ord.
define new shared variable transtype as character initial "RCT-WO".
define new shared variable total_lotserial_qty like sr_qty.
define new shared variable comp like ps_comp.
define new shared variable qty like wo_qty_ord.
define new shared variable leadtime like pt_mfg_lead.
define new shared variable prev_release like wo_rel_date.
define new shared variable prev_due like wo_due_date.
define new shared variable deliv like wod_deliver.
define new shared variable any_issued like mfc_logical.
define new shared variable conv like um_conv label "Conversion" no-undo.
define new shared variable pl_recno as recid.
define new shared variable multi_entry like mfc_logical label "Multi Entry"
   no-undo.
define new shared variable lotserial_control like pt_lot_ser.
define new shared variable site like sr_site no-undo.
define new shared variable location like sr_loc no-undo.
define new shared variable lotref like sr_ref format "x(8)" no-undo.
define new shared variable lotserial_qty like sr_qty no-undo.
define new shared variable cline as character.
define new shared variable issue_or_receipt as character.
define new shared variable trans_um like pt_um.
define new shared variable trans_conv like sod_um_conv.

define shared variable h_wiplottrace_procs as handle no-undo.
define shared variable h_wiplottrace_funcs as handle no-undo.
define shared variable wo_recid as recid.
define shared variable ophist_recid as recid.
define shared variable lotserial like sr_lotser no-undo.
define shared variable wo_recno as recid.
define shared variable eff_date like glt_effdate.

define variable rpsnbr like mrp_nbr.
define variable rpsrecord like rps_record.
define variable nbr like wo_nbr.
define variable yn like mfc_logical.
define variable rmks like tr_rmks.
define variable serial like tr_serial.
define variable ref like glt_ref.
define variable loc like ld_loc.
define variable lot like ld_lot.
define variable i as integer.
define variable trqty like tr_qty_chg.
define variable qty_left like tr_qty_chg.
define variable lotqty like wo_qty_chg.
define variable totlotqty like wo_qty_chg.
define variable null_ch as character initial "".
define variable del-yn like mfc_logical.
define variable um like pt_um no-undo.
define variable tot_units like wo_qty_chg label "Total Units".
define variable fas_wo_rec as character.
define variable temp_qty like wo_qty_chg.
define variable lotnext like wo_lot_next .
define variable lotprcpt like wo_lot_rcpt no-undo.
define variable newlot like pod_lot_next.
define variable trans-ok like mfc_logical.
define variable alm_recno as recid.
define variable filename as character.
define variable almr like alm_pgm.
define variable ii as integer.
define variable std_rework_trans as logical no-undo.
define variable rework_qty as decimal no-undo.
define variable rework_conv as decimal no-undo.
define variable rework_um as character no-undo.

define buffer rpsmstr for rps_mstr.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/

{&REISRC02-P-TAG1}

assign
   issue_or_receipt = getTermLabel("RECEIPT",8)
   tr-ok = no.

find first clc_ctrl no-lock no-error.
if not available clc_ctrl then do:
   {gprun.i ""gpclccrt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   find first clc_ctrl no-lock.
end.

undo-update = yes.

find op_hist no-lock where recid(op_hist) = ophist_recid no-error.
find wo_mstr where recid(wo_mstr) = wo_recid no-error.
find pt_mstr where pt_part = wo_part no-lock no-error.

lotprcpt = wo_lot_rcpt.

if available pt_mstr then do:

   if pt_lot_ser = "L" and not pt_auto_lot then
      lotserial = wo_lot_next.

   if (pt_lot_ser = "L" and pt_auto_lot = yes and pt_lot_grp <> "")
   then do:

      find alm_mstr where alm_lot_grp = pt_lot_grp
                      and alm_site = wo_site
      no-lock no-error.

      if not available alm_mstr then
      find alm_mstr where alm_lot_grp = pt_lot_grp
                      and alm_site = ""
      no-lock no-error.

      if not available alm_mstr then do:
         {pxmsg.i &MSGNUM=2737 &ERRORLEVEL=3}
         /* LOT FORMAT RECORD DOES NOT EXIST */
         leave.
      end.

      else do:

         if (search(alm_pgm) = ?) then do:
            ii = index(alm_pgm,".p").
            almr = global_user_lang_dir + "/" +
                   substring(alm_pgm, 1, 2) + "/" +
                   substring(alm_pgm,1,ii - 1) + ".r".
            if (search(almr)) = ? then do:
               /* AUTO LOT PROGRAM NOT FOUND */
               {pxmsg.i &MSGNUM=2732 &ERRORLEVEL=4 &MSGARG1=alm_pgm}
               leave.
            end.
         end.

      end.

      find first sr_wkfl where sr_userid = mfguser
                           and sr_lineid = cline
      no-lock no-error.

      if available sr_wkfl then
         lotserial = sr_lotser.

      filename = "wo_mstr".

      if newlot = "" then do:

         alm_recno = recid(alm_mstr).

         /* The following command is so 'gpauto01.p' is included */
         /* in the application compile cross-reference process   */
         if false then do:
            {gprun.i ""gpauto01.p""
               "(input alm_recno,
                 input wo_recno,
                 input "filename",
                 output newlot,
                 output trans-ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         /* This is the ACTUAL command that gets executed...*/
         {gprun.i alm_pgm
            "(input alm_recno,
              input wo_recno,
              input "filename",
              output newlot,
              output trans-ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if not trans-ok then do:
            /* LOT FORMAT RECORD DOES NOT EXIST */
            {pxmsg.i &MSGNUM=2737 &ERRORLEVEL=3}
            leave.
         end.

         lotserial = newlot.

         release alm_mstr.

      end. /* NEWLOT = "" */

   end. /* if pt_lot_ser = "L"..*/

end. /* if available pt_mstr */

if is_wiplottrace_enabled()
and is_woparent_wiplot_traced(op_wo_lot)
then do:

   if not
   (available pt_mstr and
       pt_auto_lot
   and pt_lot_ser = "L"
   and pt_lot_grp <> "")
   then do:

      cline = "+" + wo_part.
      i = 0.

      for each sr_wkfl no-lock where sr_userid = mfguser
                                 and sr_lineid = cline:
         i = i + 1.
         if i > 1 then leave.
      end.

      if i = 1 then do:

         for first sr_wkfl where sr_userid = mfguser
                             and sr_lineid = cline
         no-lock: end.

         assign
            site = sr_site
            location = sr_loc
            lotserial = sr_lotser
            lotref = sr_ref
                     .
      end.

   end.

end.

/* IF THIS RECORD WAS CREATED BY THE STD REPET REWORK
   TRANS, THEN DEFAULT IN QUANTITY AND CONV AND DON'T
   PROMPT FOR LOT/SERIAL, QTY, CONV, OR MULTI-ENTRY*/

std_rework_trans = false.

for first sr_wkfl where sr_userid = mfguser and sr_to_loc = 'wltstrwk'
no-lock:
   assign
      rework_qty = sr_qty
      rework_conv = decimal(sr_vend_lot)
      rework_um = sr_rev
      std_rework_trans = true.
end.

if available wo_mstr then do:

   assign
      wo_qty_chg  = op_qty_comp
      wo_rjct_chg = 0
      wo_bo_chg   = 0
      eff_date    = op_date
      total_lotserial_qty = op_qty_comp.

   
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
      
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
pt_desc1       colon 15 pt_lot_ser
      pt_desc2       at 17    no-label
      skip(1)
      lotserial_qty  colon 15 um      conv colon 50
      site           colon 15    tot_units colon 50 pt_um no-label
      location       colon 15
      lotserial      colon 15
      lotref         colon 15
      multi_entry    colon 15
    SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space
    NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = (getFrameTitle("RECEIPT_DATA_INPUT",26)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



   /* SET EXTERNAL LABELS */
   setFrameLabels(frame a:handle).

   /* DISPLAY */
   mainloop:
   do on error undo, retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


      {mfdel.i sr_wkfl
         "where sr_userid = mfguser and sr_lineid begins ""+"""}

      {gprun.i ""gplotwdl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      nbr = wo_nbr.
      status input.

      um = "".
      lotserial_control = "".
      conv = 1.

      if available pt_mstr then do:
         um = pt_um.
         lotserial_control = pt_lot_ser.
         display
            pt_desc1
            pt_desc2
            pt_lot_ser
            lotserial
         with frame a.
      end.
      else do:
         display
            "" @ pt_desc1
            "" @ pt_desc2
            "" @ pt_lot_ser
         with frame a.
      end.

      setd:
      repeat on endkey undo mainloop, leave mainloop:
/*GUI*/ if global-beam-me-up then undo, leave.


         assign
            location = ""
            lotserial_qty = total_lotserial_qty
            cline = "+" + wo_part
            global_part = wo_part
            i = 0.

         for each sr_wkfl where sr_userid = mfguser
            and sr_lineid = cline
         no-lock:
            i = i + 1.
            if i > 1 then leave.
         end.

         if i = 0 and available pt_mstr then do:
            location = pt_loc.
         end.
         else if i = 1 then do:
            find first sr_wkfl where sr_userid = mfguser
                                 and sr_lineid = cline
            no-lock.
            assign
               site = sr_site
               location = sr_loc
               lotserial = sr_lotser
               lotref = sr_ref.
         end.

         if i = 0 then site = wo_site.

         if std_rework_trans then do:

            assign
               lotserial_qty = rework_qty
               conv = rework_conv
               um = rework_um.

            display
               lotserial_qty
               conv
               um
            with frame a.

         end.

         locloop:
         do on error undo, retry on endkey undo mainloop, leave mainloop:
/*GUI*/ if global-beam-me-up then undo, leave.


            display lotserial with frame a.

            update
               lotserial_qty  when (not std_rework_trans)
               um             when (not std_rework_trans)
               conv           when (not std_rework_trans)
               site
               location
               lotserial      when (not std_rework_trans and
                                   (not (available pt_mstr and pt_auto_lot and
                                         pt_lot_grp <> "" and pt_lot_ser = "L")))
               lotref         when (not std_rework_trans)
               multi_entry    when (not std_rework_trans)
            with frame a editing:

               assign
                  global_site = input site
                  global_loc  = input location
                  global_lot  = input lotserial.

               readkey.
               apply lastkey.

            end.

            if lotref = "" and
               can-find(whl_mstr where whl_site = site
                                   and whl_loc = location no-lock)
            then do:
               find loc_mstr where loc_site = site
                               and loc_loc = location no-lock.
               assign lotref = loc_status.
            end.

            if available pt_mstr then do:
               if um <> pt_um then do:
                  if um entered and not conv entered then do:
                     {gprun.i ""gpumcnv.p"" "(input um,
                       input pt_um,
                       input wo_part,
                       output conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                     if conv = ? then do:
                        /* UOM Conversion not found */
                        {pxmsg.i &MSGNUM=33 &ERRORLEVEL=2}
                        conv = 1.
                     end.
                     display conv with frame a.
                  end. /* if um entered..*/
               end. /* if um <> pt_um */
            end. /* if available pt_mstr */

            if (clc_lotlevel = 1) and (lotserial <> "") then do:

               find first lot_mstr where lot_serial = lotserial
                                     and lot_part = wo_part
               no-lock no-error.

               if available lot_mstr and
                  (lotprcpt = yes or lot_line <> wo_lot)
               then do:
                  /* Lot is in use */
                  {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
                  next-prompt lotserial with frame a.
                  undo, retry.
               end.

               find first lotw_wkfl where lotw_lotser = lotserial
                                      and lotw_mfguser <> mfguser
                                      and lotw_part <> wo_part
               no-lock no-error.

               if available lotw_wkfl then do:
                  /* Lot is in use */
                  {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
                  next-prompt lotserial with frame a.
                  undo, retry.
               end.

            end. /* if (clc_lotlevel = 1 */

            if (clc_lotlevel = 2) and (lotserial <> "") then do:

               find first lot_mstr where lot_serial = lotserial
               no-lock no-error.

               if available lot_mstr and
                  (lotprcpt = yes or lot_line <> wo_lot)
               then do:
                  /* Lot is in use */
                  {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
                  next-prompt lotserial with frame a.
                  undo, retry.
               end.

               find first lotw_wkfl where lotw_lotser = lotserial
               no-lock no-error.
               if available lotw_wkfl then do:
                  /* Lot is in use */
                  {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
                  next-prompt lotserial with frame a.
                  undo, retry.
               end.

            end. /* if (clc_lotlevel = 2 or lotserial <> "" */

            i = 0.

            for each sr_wkfl no-lock where sr_userid = mfguser
                                       and sr_lineid = cline:
               i = i + 1.
               if i > 1 then do:
                  multi_entry = yes.
                  leave.
               end.
            end.

            assign
               trans_um   = um
               trans_conv = conv
               temp_qty   = lotserial_qty.

            if multi_entry then do:

               if i >= 1 then do:
                  assign
                     site = ""
                     location = ""
                     lotref = "".
               end.

               if (lotprcpt = yes) then lotnext = lotserial.

               /* ADDED SIXTH INPUT PARAMETER AS NO */
               {gprun.i ""icsrup.p""
                  "(input wo_site,
                    input """",
                    input """",
                    input-output lotnext,
                    input lotprcpt,
                    input no)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            end. /* if multi_entry */

            else do:

               {gprun.i ""icedit.p""
                  "(input ""RCT-WO"",
                    input site,
                    input location,
                    input wo_part,
                    input lotserial,
                    input lotref,
                    input lotserial_qty * trans_conv,
                    input trans_um,
                    input """",
                    input """",
                    output yn)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               if yn then undo locloop, retry.

               if wo_site <> site then do:

                  {gprun.i ""icedit4.p""
                     "(input ""RCT-WO"",
                       input wo_site,
                       input site,
                       input pt_loc,
                       input location,
                       input wo_part,
                       input lotserial,
                       input lotref,
                       input lotserial_qty
                       * trans_conv,
                       input trans_um,
                       input """",
                       input """",
                       output yn)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if yn then undo locloop, retry.

               end. /* if wo_site <> site */

               find first sr_wkfl where sr_userid = mfguser
                                    and sr_lineid = cline
               no-error.

               if lotserial_qty = 0 then do:

                  if available sr_wkfl then do:
                     total_lotserial_qty = total_lotserial_qty - sr_qty.
                     delete sr_wkfl.
                  end.

               end.

               else do:

                  if available sr_wkfl then do:
                     assign
                        total_lotserial_qty = total_lotserial_qty -
                                              sr_qty + lotserial_qty
                        sr_site = site
                        sr_loc = location
                        sr_lotser = lotserial
                        sr_ref = lotref
                        sr_qty = lotserial_qty.
                  end.

                  else do:

                     create sr_wkfl.
                     assign
                        sr_userid = mfguser
                        sr_lineid = cline
                        sr_site = site
                        sr_loc = location
                        sr_lotser = lotserial
                        sr_ref = lotref
                        sr_qty = lotserial_qty
                        total_lotserial_qty = lotserial_qty.

                     recno = recid(sr_wkfl).
                  end.

               end.

            end. /* if not multi_entry */

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* locloop */

         tot_units = total_lotserial_qty * conv.

         display
            tot_units
            pt_um
         with frame a.

         i = 0.

         for each sr_wkfl where sr_userid = mfguser
                            and sr_lineid = cline
         no-lock:
            i = i + 1.
            if i > 1 then leave.
         end.

         if i > 1
         then do on endkey undo mainloop, retry mainloop:

            yn = yes.
            /* Display lotserials being received */
            {pxmsg.i &MSGNUM=359 &ERRORLEVEL=1 &CONFIRM=yn}

            if yn then do:

               hide frame a.

               for each sr_wkfl where sr_userid = mfguser
                                  and sr_lineid = cline
               no-lock with frame b width 80 no-attr-space
               title (getFrameTitle("RECEIPT_DATA_REVIEW",28)):

                  /* SET EXTERNAL LABELS */
                  setFrameLabels(frame b:handle).

                  display
                     sr_site
                     sr_loc
                     sr_lotser
                     sr_ref format "x(8)" column-label "Ref"
                     sr_qty um.

               end.

            end.

         end. /* if i > 1 */

         do on endkey undo mainloop, retry mainloop:

            if temp_qty <> total_lotserial_qty then do:

               display
                  total_lotserial_qty @ lotserial_qty
               with frame a.

               /* Total lotserial quantity entered: # */
               {pxmsg.i &MSGNUM=300 &ERRORLEVEL=2
                        &MSGARG1=total_lotserial_qty
                        &MSGARG2=um}
            end.

            yn = yes.
            /* Is all information correct? */
            {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=yn}

                 
            if yn = ? then
            undo mainloop, leave mainloop.   

            if yn then do:

               {&REISRC02-P-TAG2}
               if index("LS",lotserial_control) > 0 then
               for each sr_wkfl where sr_userid = mfguser
                                  and sr_lineid = cline
                                  and sr_lotser = ""
               no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.

                  /* Lot/Serial Number required */
                  {pxmsg.i &MSGNUM=1119 &ERRORLEVEL=3}
                  next setd.
               end.
/*GUI*/ if global-beam-me-up then undo, leave.


               if conv <> 1 then
               for each sr_wkfl where sr_userid = mfguser
                                  and sr_lineid = cline:
                  sr_qty = sr_qty * conv.
               end.

               total_lotserial_qty = total_lotserial_qty * conv.

               leave setd.

            end.

         end.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*setd*/

      hide frame a.
      hide frame b.

      wo_qty_chg = total_lotserial_qty.
      undo-update = no.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


end.

tr-ok = yes.
